package fun.wlfj.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fun.wlfj.factory.CashSystemFactory;
import fun.wlfj.vo.Product;

/**
 * Servlet implementation class QueryProductServlet
 */
@WebServlet("/QueryProductServlet")
public class QueryProductServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public QueryProductServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.getWriter().append("Do not request me directly! QwQ");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String ProductShortName = (String)request.getParameter("ProductShortName");
		if(ProductShortName != null) {
			List<Product> list = CashSystemFactory.getProductDao().findByShortName(ProductShortName);
			if(list.size() > 0) {
				request.setAttribute("ProductInfo", list.get(0));
				request.getRequestDispatcher("makePay.jsp").forward(request, response);
				return;
			}
		}
		response.sendRedirect("makePay.jsp");
	}

}
